package org.jeecg.modules.job.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.job.ums.entity.UmsChatHistory;
import org.jeecg.modules.job.ums.service.IUmsChatHistoryService;
import org.jeecg.modules.job.utils.JsonUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/goeasy")
@Api(tags="goeasy消息同步接口")
@Slf4j
@CrossOrigin
public class WebhookController{

    @Resource
    private IUmsChatHistoryService chatHistoryService;

    /**
     * 同步消息
     */
    @ResponseBody
    @RequestMapping(value = "/syncHistory",method = RequestMethod.POST)
    @ApiOperation(value = "同步消息", notes = "同步消息")
    public Result syncHistory(String content) {
        try {
            if(!"[]".equals(content)){
                List<UmsChatHistory> list = JsonUtils.jsonToList(content, UmsChatHistory.class);
                System.out.println("--------------同步消息-----------------");
                System.out.println(list.toString());
                chatHistoryService.addBatch(list);
            }
            return Result.ok();
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }


}